const { update, get } = require('../../helper/db');
const { door, ok } = require('../../helper/util');

/**
 * @apiDefine ErrorResponse
 * @apiError (请求错误) {String} err_message 错误信息描述
 */

/**
 * @apiVersion 1.0.0
 * @apiGroup 好友
 * @api {POST} api/friend/updateRemark 更新好友的备注
 * @apiName api/friend/updateRemark
 * @apiExample {js} axios 例子:
 *  axios.post('http://39.105.38.34:8080/api/friend/updateRemark', {
 *    relationID: 1,
 *    remark: '陈浩天',
 *  });
 * @apiParam  {String} relationID 申请中的好友关系的 ID
 * @apiParam  {String} remark 给好友的备注
 * @apiSuccess (请求成功) {Object} relation 好友关系数据
 * @apiuse  ErrorResponse
 */

module.exports = async ctx => {
  var token = ctx.headers.authorization;
  var params = ctx.request.body;
  var user = await door(token);
  var relation = await get('relation_ship', params.relationID);

  var relation = await update('relation_ship', {
    ...relation,
    remark: params.remark,
    id: params.relationID,
  });

  ctx.body = ok(relation);
}
